package com.gewu.pm.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;

/**
 * 配送商详情 - 终端列表Adapter
 * 
 * 功能：
 * 1. 显示终端列表
 * 2. 支持点击Item
 * 
 * 注意：
 * - 暂时只显示终端名称（String类型）
 * - 后期可修改为完整的终端Bean
 */
public class DeliveryTerminalAdapter extends AppAdapter<String> {

    public DeliveryTerminalAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new TerminalViewHolder();
    }

    /**
     * 终端Item ViewHolder
     */
    private final class TerminalViewHolder extends AppAdapter<?>.ViewHolder {
        
        private final TextView mTerminalNameView;
        private final TextView mTerminalAddressView;
        private final TextView mTerminalCodeView;
        private final TextView mTerminalTypeView;
        private final TextView mVehicleCodeView;
        private final TextView mDistributorView;
        private final TextView mSalespersonView;
        
        private TerminalViewHolder() {
            super(R.layout.delivery_terminal_item);
            mTerminalNameView = findViewById(R.id.tv_terminal_name);
            mTerminalAddressView = findViewById(R.id.tv_terminal_address);
            mTerminalCodeView = findViewById(R.id.tv_terminal_code);
            mTerminalTypeView = findViewById(R.id.tv_terminal_type);
            mVehicleCodeView = findViewById(R.id.tv_vehicle_code);
            mDistributorView = findViewById(R.id.tv_distributor);
            mSalespersonView = findViewById(R.id.tv_salesperson);
            
            // BaseAdapter 会自动设置点击事件，无需手动添加
        }
        
        @Override
        public void onBindView(int position) {
            String terminalName = getItem(position);
            // 暂时只设置终端名称
            mTerminalNameView.setText(terminalName);
            
            // 其他字段使用XML中的默认值
            // 后期可根据Bean对象动态赋值
            // mTerminalAddressView.setText(terminal.getAddress());
            // mTerminalCodeView.setText(terminal.getCode());
            // ...
        }
    }
}

